From be13de0679d1707eadaf5349ab904a07fa83bb13 Mon Sep 17 00:00:00 2001
From: phunkyfish <phunkyfish@gmail.com>
Date: Wed, 7 Oct 2020 17:34:56 +0100
Subject: [PATCH] Remove p8 os includes

Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
---
 src/Socket.cpp                  |  1 -
 src/lib/tsreader/FileReader.h   |  1 -
 src/lib/tsreader/MemorySink.cpp |  1 -
 src/lib/tsreader/Section.cpp    |  2 ++
 src/os-dependent.h              | 40 ++++++++++++++++++---------------
 src/timers.cpp                  |  1 -
 src/windows/FileUtils.cpp       |  6 ++++-
 7 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/src/Socket.cpp b/src/Socket.cpp
index 12f7e80..b7dd250 100644
--- a/src/Socket.cpp
+++ b/src/Socket.cpp
@@ -7,7 +7,6 @@
 
 #include "utils.h"
 #include <string>
-#include "p8-platform/os.h"
 #include "Socket.h"
 
 #include <kodi/General.h>
diff --git a/src/lib/tsreader/FileReader.h b/src/lib/tsreader/FileReader.h
index 986bbc4..edb01f2 100644
--- a/src/lib/tsreader/FileReader.h
+++ b/src/lib/tsreader/FileReader.h
@@ -33,7 +33,6 @@
  *  http://forums.dvbowners.com/
  */
 
-#include "p8-platform/os.h" // for __stat
 #include <string>
 #include <kodi/Filesystem.h>
 
diff --git a/src/lib/tsreader/MemorySink.cpp b/src/lib/tsreader/MemorySink.cpp
index 2d60696..dafef56 100644
--- a/src/lib/tsreader/MemorySink.cpp
+++ b/src/lib/tsreader/MemorySink.cpp
@@ -29,7 +29,6 @@
 
 #if defined LIVE555
 
-#include "p8-platform/os.h"
 #include "MemorySink.h"
 #include "GroupsockHelper.hh"
 #include <kodi/General.h> //for kodi::Log
diff --git a/src/lib/tsreader/Section.cpp b/src/lib/tsreader/Section.cpp
index 258c6a9..aac6b53 100644
--- a/src/lib/tsreader/Section.cpp
+++ b/src/lib/tsreader/Section.cpp
@@ -22,6 +22,8 @@
 #include "os-dependent.h"
 #include "Section.h"
 
+#include <cstring>
+
 namespace MPTV
 {
     CSection::CSection(void)
diff --git a/src/os-dependent.h b/src/os-dependent.h
index 1f368ea..cdc6980 100644
--- a/src/os-dependent.h
+++ b/src/os-dependent.h
@@ -7,29 +7,33 @@
 
 #pragma once
 
-#include "p8-platform/os.h"
+#include <cstdint>
 
-#ifdef TARGET_LINUX
-// Retrieve the number of milliseconds that have elapsed since the system was started
-#include <time.h>
-inline unsigned long long GetTickCount64(void)
-{
-  struct timespec ts;
-  if(clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
-  {
-    return 0;
-  }
-  return (unsigned long long)( (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000) );
-};
-#elif defined(TARGET_DARWIN)
-#include <time.h>
+#if (defined(_WIN32) || defined(_WIN64))
+
+#ifndef _SSIZE_T_DEFINED
+#ifdef  _WIN64
+typedef __int64    ssize_t;
+#else
+typedef _W64 int   ssize_t;
+#endif
+#define _SSIZE_T_DEFINED
+#endif
+
+#else
+
+#if (defined(TARGET_LINUX) || defined(TARGET_DARWIN))
+#include <sys/types.h>
+#include <chrono>
+#include <cstring>
 inline unsigned long long GetTickCount64(void)
 {
-  struct timeval tv;
-  gettimeofday(&tv, NULL);
-  return (unsigned long long)( (tv.tv_sec * 1000) + (tv.tv_usec / 1000) );
+  auto now = std::chrono::steady_clock::now();
+  return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
 };
 #endif /* TARGET_LINUX || TARGET_DARWIN */
 
+#endif
+
 // Additional typedefs
 typedef uint8_t byte;
diff --git a/src/timers.cpp b/src/timers.cpp
index a8760e4..a60b4c2 100644
--- a/src/timers.cpp
+++ b/src/timers.cpp
@@ -11,7 +11,6 @@
 
 using namespace std;
 
-#include "p8-platform/os.h" //needed for snprintf
 #include "timers.h"
 #include "settings.h"
 #include "utils.h"
diff --git a/src/windows/FileUtils.cpp b/src/windows/FileUtils.cpp
index 0d26bc6..0c8a03e 100644
--- a/src/windows/FileUtils.cpp
+++ b/src/windows/FileUtils.cpp
@@ -6,7 +6,6 @@
  */
 
 #include "../FileUtils.h"
-#include "p8-platform/os.h"
 #include "p8-platform/windows/CharsetConverter.h"
 #include <string>
 #include "../utils.h"
@@ -14,6 +13,11 @@
 #include <Shlobj.h>
 #endif
 
+#ifdef TARGET_WINDOWS
+#include <windows.h>
+#include <fileapi.h>
+#endif
+
 namespace OS
 {
   bool CFile::Exists(const std::string& strFileName, long* errCode)
